package com.mm.cme.kotlin_001.level03_object_oriented_program.conflict

import com.mm.cme.kotlin_001.utils.pl

/**
 * Descriptions：继承中的冲突
 * <p>
 * Author：ChenME
 * Date：2017/7/17
 * Email：ibelieve1210@163.com
 */

abstract class A {
    open fun x(): Int = 5
}

interface B {
    fun x(): Int = 1
}

interface C {
    fun x(): Int = 0
}

class D(val y: Int = 0) : A(), B, C {

    override fun x(): Int {

        pl("call x():Int in D")
        if (y > 0) {
            return y
        } else if (y < -200) {
            return super<C>.x()
        } else if (y < -100) {
            return super<B>.x()
        } else {
            return super<A>.x()
        }
    }
}


fun main(args: Array<String>) {
    pl(D(3).x())
    pl(D(-1).x())
    pl(D(-110).x())
    pl(D(-1100).x())
}